﻿@using PersonalWebSite.Common
@model PersonalWebSite.Models.ActivityViewModel
@{
    ViewBag.Title = "Hintea Dan Alexandru - Latest Activities";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div id="UniverseHolderWrapper">
    <div class="hdunv-fixture"> 
        <div data-hdunv_type="Universe" data-hdunv_x="0" data-hdunv_y="0" data-hdunv_w="1000" data-hdunv_h="350" data-hdunv_name="hD Universe" data-starfield_enabled="false" data-shootingstar_enabled="false">
            <div class="hdunv-content"></div>

            <div data-hdunv_type="Galaxy" data-hdunv_depth="0" data-hdunv_x="0" data-hdunv_y="0" data-hdunv_w="50" data-hdunv_h="350" data-hdunv_name="Header">
                <div data-hdunv_type="SolarSystem" data-hdunv_speed="0" data-hdunv_direction="cw" data-hdunv_x="0" data-hdunv_y="0" data-hdunv_w="0" data-hdunv_h="0" data-hdunv_name="MainSection Top">
                    <div class="hdunv-content">
                        @{Html.RenderAction("Button", "Tiles", new { IconName = "Home", Tip = "Home", NavigateUrl = Url.Action("Index", "Home") });}
                    </div>
                </div>
                @if (Model.PageIndex > 0)
                {
                <div data-hdunv_type="SolarSystem" data-hdunv_speed="0" data-hdunv_direction="cw" data-hdunv_x="0" data-hdunv_y="0" data-hdunv_w="0" data-hdunv_h="0" data-hdunv_name="MainSection Top">
                    <div class="hdunv-content">
                        @{Html.RenderAction("Button", "Tiles", new { IconName = "Rewind", Tip = "View Latest", NavigateUrl = Url.Action("Index") });}
                    </div>
                </div>
                <div data-hdunv_type="SolarSystem" data-hdunv_speed="0" data-hdunv_direction="cw" data-hdunv_x="0" data-hdunv_y="0" data-hdunv_w="0" data-hdunv_h="0" data-hdunv_name="MainSection Top">
                    <div class="hdunv-content">
                        @{Html.RenderAction("Button", "Tiles", new { IconName = "Back", Tip = "View Earlier", NavigateUrl = Url.Action("Index", new { pageIndex = Model.PageIndex - 1 }) });}
                    </div>
                </div>
                }
                <div data-hdunv_type="SolarSystem" data-hdunv_speed="0" data-hdunv_direction="cw" data-hdunv_x="0" data-hdunv_y="0" data-hdunv_w="0" data-hdunv_h="0" data-hdunv_name="MainSection Top">
                    <div class="hdunv-content">
                        @{Html.RenderAction("Button", "Tiles", new { IconName = "Forward", Tip = "View Older", NavigateUrl = Url.Action("Index", new { pageIndex = Model.PageIndex + 1 }) });}
                    </div>
                </div>
            </div>

            <!-- ko foreach: { data: ActivityFeed.ItemsToDisplay} -->
            <div data-hdunv_type="Galaxy" data-hdunv_depth="0" data-hdunv_x="0" data-hdunv_y="0" data-hdunv_w="350" data-hdunv_h="350" data-hdunv_name="Header">
                <div data-hdunv_type="SolarSystem" data-hdunv_speed="0" data-hdunv_direction="cw" data-hdunv_x="0" data-hdunv_y="0" data-hdunv_w="0" data-hdunv_h="0" data-hdunv_name="MainSection Top">
                    <div class="hdunv-content">
                        @{Html.RenderAction("Activity", "Tiles");}
                    </div>
                </div>
            </div>
            <!-- /ko -->

        </div>
    </div>
</div>

<script type="text/javascript">
    $(window).resize(function () {
        $("#UniverseHolderWrapper").css("height", $(window).outerHeight());
    });
    $("#UniverseHolderWrapper").css("height", $(window).outerHeight());

    var PageViewModel = {
        ActivityFeed: {},

        embedVideoPlayClick: function (dataItem, event) {
            var activityMaterialJq = $(event.target).closest(".ActivityMaterial");
            ModalOverlay.Show('<div style="text-align: center; position: absolute; top: 50px; width: 100%;"><iframe width="100%" height="700" src="' + dataItem.EmbedUrl + '" frameborder="0" allowfullscreen="1"></iframe></div>', true);
        }
    };

    var fetchActivitiesAjaxIconId = -1; _hD.push(function () { fetchActivitiesAjaxIconId = AjaxIconToggle(true); });
    $.ajax('@Url.Action("Activities", "Activity", new { pageIndex = Model.PageIndex })', {
        complete: function (jqXHR, textStatus) {
            if (AjaxIconToggle)
                AjaxIconToggle(false, fetchActivitiesAjaxIconId);
            else
                _hD.push(function () { AjaxIconToggle(false, fetchActivitiesAjaxIconId); });
        },
        success: function (data, textStatus, jqXHR) {
            PageViewModel.ActivityFeed = data;
            InitActivityTiles();
        },
        error: function (jqXHR, textStatus, errorThrown) {
            NotifierShow('Some error occured while trying to retrieve the activities. I\'m very sorry for that, please try again by refreshing the page.', 'This page depends on some external services like Google\'s Plus Service. It may happen that these services are not available sometimes so again, sorry for the inconvenience and please try again to reload the page.');
        }
    });

    function InitActivityTiles() {
        ko.applyBindings(PageViewModel, $(".hdunv-fixture")[0]);

        var universe = new hDUnivSim("#UniverseHolderWrapper", new MetroStyleDrawer(), InPageHtmlFixture);
        universe.AlignHorizontal = Align.Horizontal.Left;
        universe.InitHtml();

        InitMetroTilesColouringEffect();
    };
</script>